@*
	For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
	Layout = "_Layout";
}
<body class="layui-anim layui-anim-up">
	<div class="x-nav">
		<span class="layui-breadcrumb">
			<a href="/Admin/Admin/Index">首页</a>
			<a>
				<cite>Banner管理</cite>
			</a>
		</span>
		<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
			<i class="layui-icon" style="line-height:30px">ဂ</i>
		</a>
	</div>
	<div class="x-body">
		<xblock>
			<button class="layui-btn j-add" ><i class="layui-icon"></i>添加</button>
		</xblock>
		<table class="layui-table" lay-data="{ url:'/Admin/Banner/GetBanner', page:true, id:'banner'}" lay-filter="banner">
			<thead>
				<tr>
					<th lay-data="{field:'', width:'5%', sort: true,type:'numbers'}">ID</th>
					<th lay-data="{field:'Title', width:'10%'}">标题</th>
					<th lay-data="{field:'State', width:'8%',templet: '#barIsEnabled'}">状态</th>
					<th lay-data="{field:'Describe', width:'20%'}">描述</th>
                    <th lay-data="{field:'TypeStr', width:'7%'}">类型</th>
					<th lay-data="{field:'ImgUrl', width:'20%', templet: '#imgUrl'}">图片地址</th>
					<th lay-data="{field:'HrefUrl' , width:'15%'}">链接地址</th>
					<th lay-data="{field:'' , width:'15%' , templet: '#barDemo'}">操作</th>
				</tr>
			</thead>
		</table>

		<script type="text/html" id="imgUrl">
			<a href="{{d.ImgUrl}}" target="_blank">{{d.ImgUrl}}</a>
		</script>

		<script type="text/html" id="barIsEnabled">
			{{#  if(d.State){ }}
			<input type="checkbox" checked="" lay-skin="switch" lay-text="启用|禁用" lay-filter="ChkIsEnableds" aid="{{ d.Id }}">
			{{#  }else{ }}
			<input type="checkbox" lay-skin="switch" lay-text="启用|禁用" lay-filter="ChkIsEnableds" aid="{{ d.Id }}">
			{{#  } }}
		</script>

		<script type="text/html" id="barDemo">
			@*<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>*@
			<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
		</script>

	</div>
	<script>

		layui.use(['laydate', 'table', 'form','layer'], function () {
			var laydate = layui.laydate;
			var table = layui.table;
			var $ = layui.jquery;
			var form = layui.form;
			var layer=layui.layer;

			//启用、禁用
			form.on('switch(ChkIsEnableds)', function (data) {
				var sw = this;
				var vn = sw.checked ? "启用" : "禁用";
				var vis = sw.checked ? true : false;
				var vcid = $(sw).attr("aid");
				var x = sw.checked;
				HsCms.Confirm("您确定" + vn + "该数据吗？", function () {
					HsCms.AjaxPost("/Admin/Banner/IsEnabled", "Id=" + vcid + "&isEnabled=" + vis, function (result) {
						if (result.code === 1) {
							table.reload("banner");
						}
						else {
							sw.checked = !x;
							form.render("checkbox");
						}
						HsCms.Msg(result.msg);
					});
				}, function () {
					sw.checked = !x;
					form.render("checkbox");
				}, function () {
					sw.checked = !x;
					form.render("checkbox");
				});
			});

			//监听行工具事件
			table.on('tool(banner)', function (obj) {
				var data = obj.data;
				//console.log(obj)
				if (obj.event === 'del') {
					layer.confirm('真的删除行么', function (index) {

						$.ajax({
							type: "post",
							url: "/Admin/Banner/Del",
							data: { id: data.Id },
							success: function (result) {
								if (result.state == "ok") {
									layer.msg(result.msg)
								} else {
									layer.msg(result.msg)
								}
							}
						})

						obj.del();

					});
				} else if (obj.event === 'edit') {
					layer.prompt({
						formType: 2
						, value: data.email
					}, function (value, index) {
						obj.update({
							email: value
						});
						layer.close(index);
					});
				}
			});

			$(".j-add").click(function () {
				//var langstr = langs.join(',');
				HsCms.OpenPart(2, 'bann', '/Admin/Banner/Add?type=add', "新增", ['900px', '700px'], ['新增', '取消'], function (layero) {

				}, function (index, layero) {
					$(".btnEdit", layero.find("iframe")[0].contentWindow.document).click();
				});
			});


		});


	</script>
</body>